<?php

/**
 * CodeRS - Atviras kodas Lietuvai
 * Copyright (C) 2007 CodeRS www.coders.lt info@coders.lt
 * MightMedia TVS
 * Remontas - šis puslapis užkraunamas kai svetainė remontuojama arba laikinai nepasiekiama.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 * 
 * Ši programa yra laisva. Jūs galite ją platinti ir/arba modifikuoti
 * remdamiesi Free Software Foundation paskelbtomis GNU Bendrosios
 * Viešosios licencijos sąlygomis: 2 licencijos versija, arba (savo
 * nuožiūra) bet kuria vėlesne versija.
 * 
 * Ši programa platinama su viltimi, kad ji bus naudinga, bet BE JOKIOS
 * GARANTIJOS; be jokios numanomos PERKAMUMO ar TINKAMUMO KONKRETIEMS
 * TIKSLAMS garantijos. Žiūrėkite GNU Bendrąją Viešąją licenciją norėdami
 * sužinoti smulkmenas.
 * 
 * Jūs turėjote kartu su šia programa gauti ir GNU Bendrosios Viešosios
 * licencijos kopija; jei ne - rašykite Free Software Foundation, Inc., 59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**/

include_once("variklis/bendras.php");

if (isset($_POST['action']) && $_POST['action'] == 'prisijungimas') {
	$strUsername = htmlspecialchars($_POST['vartotojas']);
	$strPassword = md5($_POST['slaptazodis']);
	$linfo = $db->masyvas($db->uzklausa("SELECT id, levelis FROM users WHERE nick=" . escape($strUsername) ." AND pass='" . $strPassword ."'"));
	if (!empty($linfo)) {
    		$_SESSION['username'] = $strUsername;
    		$_SESSION['password'] = $strPassword;
    		$_SESSION['id'] = $linfo['id'];
      		define("LEVEL", $linfo['levelis']);
      		$db->uzklausa("UPDATE `users` SET `login_data` = NOW( ) WHERE `users`.`id` ='" . $linfo['id'] ."' LIMIT 1");
      		unset($linfo);
 	}
  	else {
    	$strError = 'Klaidingi duomenys';
  	}
  	unset($linfo,$strUsername,$strPassword);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="<?=$conf['Pavadinimas'].' - '.$conf['Apie']?>">
<title><?=$conf['Pavadinimas']?></title>
<link href="stilius/stilius.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascript/countdown.js" defer="defer"></script>
</head>

<body>
<table width="400px" align="center">
<tr><td>
<?
klaida("Remontas",$conf['Maintenance']);
if ($conf['Palaikymas'] == 1 && !defined("LEVEL")) {
				$text = "
					<center>".((isset($strError))?$strError:'')."
			  			<form id=\"user_reg\" name=\"user_reg\" method=\"post\" action=\"\">
							<label for=\"vartotojas\">Vartotojas:</label>
							<br />
							<input name=\"vartotojas\" type=\"text\"  value=\"\" maxlength=\"50\" />
							<br />
							<label for=\"slaptazodis\">Slaptažodis:</label>
							<br />
							<input name=\"slaptazodis\" type=\"password\" value=\"\" maxlength=\"50\" />
							<br />
							<input type=\"submit\" name=\"Submit\" value=\"Prisijungti\" />
							<input type=\"hidden\" name=\"action\" value=\"prisijungimas\" />
						</form>
					</center>";
				lentele("Vartotojams",$text,"Administratoriaus prisijungimas:");
}
elseif (ADMIN == 1) { header('location: index.php'); }
else { header('location: remontas.php'); }
?>
</td></tr></table>
<?
copyright($conf['Copyright']);
?>
</body>
</html>